package com.linln.modules.member.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.linln.common.data.PageSort;
import com.linln.modules.member.domain.Notice;
import com.linln.modules.member.repository.NoticeRepository;
import com.linln.modules.member.service.NoticeService;

/**
 * @author hct
 * @date 2019/10/11
 */
@Service
public class NoticeServiceImpl implements NoticeService {

    @Autowired
    private NoticeRepository noticeRepository;

    /**
     * 根据ID查询数据
     * @param id 主键ID
     */
    @Override
    @Transactional
    public Notice getById(Long id) {
        return noticeRepository.findById(id).orElse(null);
    }

    /**
     * 获取分页列表数据
     * @param example 查询实例
     * @return 返回分页数据
     */
    @Override
    public Page<Notice> getPageList(Example<Notice> example) {
        // 创建分页对象
        PageRequest page = PageSort.pageRequest();
        return noticeRepository.findAll(example, page);
    }

    /**
     * 保存数据
     * @param notice 实体对象
     */
    @Override
    public Notice save(Notice notice) {
        return noticeRepository.save(notice);
    }

    /**
     * 状态(启用，冻结，删除)/批量状态处理
     */
    @Override
    @Transactional
    public Boolean updateIsReadById(Integer status, List<Long> idList) {
        return noticeRepository.updateIsReadById(status, idList) > 0;
    }
     /**
     * 
     */
    @Transactional
    public Boolean updateIsReadById(Integer status, Long id) {
    	return noticeRepository.updateIsReadById(status, id) > 0;
    }
 
}